<template>
  <el-menu
    :default-active="activeIndex"
    class="el-menu-vertical-demo"
    @open="handleOpen"
    @close="handleClose"
    :collapse="isCollapse"
    background-color="#545c64"
    text-color="#fff"
    active-text-color="#ffd04b"
  >
  <h3 class="text" v-if="textManage">嗨害嗨！</h3>
    <el-menu-item
      v-for="item in noChildren"
      :index="item.path"
      :key="item.path"
      @click="clickMenu(item)"
      
    >
      <i :class="'el-icon-' + item.icon"></i>
      <span slot="title">{{ item.label }}</span>
    </el-menu-item>
    <!-- <el-submenu v-for="item in hasChildren" :key="item.path" index="item.path">
      <template slot="title">
        <i :class="'el-icon-'+item.icon"></i>
        <span slot="title">{{item.label}}</span>
      </template>

    </el-submenu> -->
   </el-menu>
</template>
<style scoped>
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
}
.el-menu{
  height: 100%;
  border: none;
  /* height: 100%; */
  height: 100vh;
}
.text{
  text-align: center;
  color: #fff;
  line-height: 48px;
}
</style>
<script>
export default {
  data() {
    return {
      // isCollapse: true,
      menu: [
        {
          path: "/home",
          name: "home",
          label: "首页",
          icon: "s-home",
          url: "Home/HOME",
        },
        {
          path: "/mall",
          name: "mall",
          label: "商品管理",
          icon: "video-play",
          url: "MallManage/MallManage",
        },
        {
          path: "/user",
          name: "user",
          label: "用户管理",
          icon: "user",
          url: "UserManage/UserManage",
        },
    
      ],
    };
  },
  methods: {
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    clickMenu(item){ 
      this.$router.push({
        name: item.name
      })
      this.$store.commit('selectMenu',item)
      // console.log(this.$store.state.tableList)
    }
    
  },
  computed: {
    noChildren() {
      // console.log(this.$store.state.menu);
    //  return this.menu.filter(item => !item.children);
    return this.$store.state.menu
    },
    // hasChildren() {
    //   return this.menu.filter(item => item.children);
    // },
    activeIndex(){
      return this.$route.path.replace('item.path')
    },
    isCollapse(){
      return this.$store.state.isCollapse
      // console.log(this.$store.state.isCollapse)
      
    },
    textManage(){
      return this.$store.state.text
    },
    

  },
};
</script>